﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WebSocketChatServer
{
    /// <summary>
    /// 响应
    /// </summary>
    public class ResponseMsg
    {
        private string? requestId;
        private int serviceId;
        private bool isSuccess;
        private string? message;
        private string name;
        /// <summary>
        /// 已经上线的客户端
        /// key:requestId(保证唯一),value:name(客户端名字)
        /// </summary>
        private Dictionary<string, string> hadOnline = new Dictionary<string, string>();

        public string? RequestId { get => requestId; set => requestId = value; }
        public int ServiceId { get => serviceId; set => serviceId = value; }
        public bool IsSuccess { get => isSuccess; set => isSuccess = value; }
        public string? Message { get => message; set => message = value; }
        public Dictionary<string, string> HadOnline { get => hadOnline; set => hadOnline = value; }
        public string Name { get => name; set => name = value; }

        public String ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        public override string ToString()
        {
            return ToJson();
        }

        public static ResponseMsg? createInstance(string json)
        {
            if (!string.IsNullOrEmpty(json))
                return JsonConvert.DeserializeObject<ResponseMsg>(json);

            return null;
        }
    }
}
